#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using System.Reflection;
using System.Collections;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class WinSDSPODetailsForm : Form
    {
        User m_current_user;
        public WinSDSPODetailsForm(jPOHeader po, User user)
        {
            InitializeComponent();
            m_current_user = user;
            listViewItems.Columns.Clear();
            FieldInfo[] column = typeof(JPODetails).GetFields();
            foreach (FieldInfo pi in column)
            {
                listViewItems.Columns.Add(pi.Name, 100, HorizontalAlignment.Left);
            }
            ListViewTools.LoadConfiguration(listViewItems, m_current_user);
            listViewItems.ColumnWidthChanged += new ColumnWidthChangedEventHandler(listViewItems_ColumnWidthChanged);
            LoadItems(po.Details);

            ListViewTools p = new ListViewTools(listViewItems, user);
        }

        void listViewItems_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
        {
            ListViewTools.SaveConfiguration(listViewItems, m_current_user);
        }

        private void LoadItems(IList details)
        {
            foreach (JPODetails a in details)
            {
                ListViewItem item = new ListViewItem();
                foreach (FieldInfo fi in typeof(JPODetails).GetFields())
                {
                    item.SubItems.Add(fi.GetValue(a) == null ? "" : fi.GetValue(a).ToString());
                }
                listViewItems.Items.Add(item); // alert date..
                item.Tag = a;
            }
        }
    }
}